#include "downloadMovieMessage.h"
#include "jsonUtils.h"

DownloadMovieMessage::DownloadMovieMessage(MtpProtocol* packet) : MtpMessage(packet),movieId(0)
{

}

DownloadMovieMessage::DownloadMovieMessage(const int64_t& movieId) : MtpMessage(new MtpProtocol(L"downloadMovie")),movieId(movieId)
{

}

void DownloadMovieMessage::decodeBody()
{
	MtpMessage::decodeBody();
	if (!jsonContent.empty()) {
		JsonDoc doc(rapidjson::kObjectType);
		doc.Parse(jsonContent.c_str());
		JsonUtils::loadLong(doc, L"movieId", movieId);
	}
}

void DownloadMovieMessage::encodeBody()
{
	JsonDoc doc(rapidjson::kObjectType);
	JsonUtils::loadLong(doc, L"movieId", movieId);
	jsonContent = JsonUtils::jsonStr(doc);
	MtpMessage::encodeBody();
}

int64_t DownloadMovieMessage::getMovieId() const
{
	return movieId;
}
